package com.learn.redis.lock;

/**
 * @author PC
 * Lock接口
 */
public interface LockService {
    ThreadLocal<CusLockInfo> CUS_LOCK_INFO_THREAD_LOCAL = ThreadLocal.withInitial(() -> null);

    default void setLockInfoThreadLocal(CusLockInfo cusLockInfo) {
        CUS_LOCK_INFO_THREAD_LOCAL.set(cusLockInfo);
    }

    default CusLockInfo getLockInfoThreadLocal() {
        return CUS_LOCK_INFO_THREAD_LOCAL.get();
    }

    default void removeLockInfoThreadLocal() {
        CUS_LOCK_INFO_THREAD_LOCAL.remove();
    }

    /**
     * 加锁
     *
     * @return 是否加锁成功
     */
    Boolean lock();

    /**
     * 加锁
     *
     * @param cusLockInfo 锁信息
     * @return 是否加锁成功
     */
    Boolean lock(CusLockInfo cusLockInfo);

    void unLock();

    void unLock(CusLockInfo cusLockInfo);

    String lockType();
}
